package com.heima.test6;

import java.util.Random;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        //定义一个生成验证码的静态方法getLoginCode，写一个登录测试类，当用户登录时提示用户输入验证码
        Scanner sc = new Scanner(System.in);
        getLoginCode();
        System.out.println();
        System.out.println("请输入验证码:");
        String name = sc.next();

    }
    public static void getLoginCode(){
        StringBuilder sb = new StringBuilder();
        Random r = new Random();

        for (char i = 'a'; i <= 'z'; i++) {
            sb.append(i);
        }
        for (char i = 'A'; i <= 'Z'; i++) {
            sb.append(i);
        }
        for (char i = '0'; i <= '9'; i++) {
            sb.append(i);
        }

        System.out.print("验证码为：");
        for (int i = 1; i <= 4; i++) {
            int index = r.nextInt(sb.length());
            System.out.print(sb.charAt(index));
        }
    }
}
